home *** CD-ROM | disk | FTP | other *** search
/ Champak 66 / Vol 66.iso / games / compulse.swf / scripts / frame_6 / DoAction.as
Encoding:
Text File  |  2013-04-24  |  12.6 KB  |  575 lines

  1. function callDescriptions()
  2. {
  3.    var _loc1_ = "L" + level;
  4.    var _loc2_ = "Par Score: " + parTimes[level - 1];
  5.    parR.text = _loc2_;
  6.    proR.text = "Pro Score: " + proScores[level - 1];
  7.    descriptR.text = _loc1_;
  8.    if(Number(totUp + totDown + totLeft + totRight) > parTimes[level - 1])
  9.    {
  10.       usedR = "Total Used: <font color=\'#990000\'>" + Number(totUp + totDown + totLeft + totRight) + "</font>";
  11.    }
  12.    else
  13.    {
  14.       usedR = "Total Used: <font color=\'#FFFFFF\'>" + Number(totUp + totDown + totLeft + totRight) + "</font>";
  15.    }
  16. }
  17. function resetCompulses()
  18. {
  19.    totLeft = totRight = totUp = totDown = 0;
  20.    holder.removeMovieClip();
  21.    createEmptyMovieClip("holder",k++);
  22.    compulses.splice(0,compulses.length);
  23. }
  24. function triggerInstantReplay()
  25. {
  26.    levelComplete.removeMovieClip();
  27.    levelMenu.removeMovieClip();
  28.    mainMode = "instantReplay";
  29.    globalPause = false;
  30.    cStatus = true;
  31.    resetMap();
  32.    playCounter = 0;
  33.    playMode = "paused";
  34.    shel = attachMovie("playControls","playControls",k++);
  35. }
  36. function backToMenu()
  37. {
  38.    killSwitch();
  39.    gotoAndStop("menu");
  40. }
  41. function replayLevel()
  42. {
  43.    globalPause = false;
  44.    cStatus = false;
  45.    resetButton._visible = true;
  46.    levelComplete.removeMovieClip();
  47.    levelMenu.removeMovieClip();
  48.    resetMap();
  49.    mainMode = "normal";
  50.    ball.gotoAndStop(1);
  51.    goButton._visible = true;
  52.    stopButton._visible = false;
  53.    resetRecordMemory();
  54. }
  55. function killSwitch()
  56. {
  57.    for(var _loc2_ in _root)
  58.    {
  59.       if(typeof _root[_loc2_] == "movieclip")
  60.       {
  61.          _root[_loc2_].removeMovieClip();
  62.       }
  63.    }
  64. }
  65. function closePlayControls()
  66. {
  67.    globalPause = true;
  68.    cStatus = false;
  69.    triggerLevelMenu();
  70.    resetMap();
  71.    mainMode = "normal";
  72.    playControls.removeMovieClip();
  73. }
  74. function nextLevel()
  75. {
  76.    level++;
  77.    levelDisp = "L" + level;
  78.    resetButton._visible = true;
  79.    clearBitmap();
  80.    resetCompulses();
  81.    callDescriptions();
  82.    levelComplete.removeMovieClip();
  83.    levelMenu.removeMovieClip();
  84.    levels.nextFrame();
  85.    globalPause = false;
  86.    cStatus = false;
  87.    stopButton._visible = false;
  88.    goButton._visible = true;
  89.    ball.gotoAndStop(1);
  90.    mainMode = "normal";
  91.    resetMap();
  92.    resetRecordMemory();
  93. }
  94. function playPoints()
  95. {
  96.    if(playMode == "normalPlay")
  97.    {
  98.       playCounter++;
  99.    }
  100.    if(playMode == "normalRewind")
  101.    {
  102.       playCounter--;
  103.    }
  104.    if(playMode == "fastPlay")
  105.    {
  106.       playCounter += 4;
  107.    }
  108.    if(playMode == "fastRewind")
  109.    {
  110.       playCounter -= 4;
  111.    }
  112.    if(playMode == "slowPlay")
  113.    {
  114.       playCounter += 0.5;
  115.    }
  116.    if(playMode == "slowRewind")
  117.    {
  118.       playCounter -= 0.5;
  119.    }
  120.    ball._x = recordX[playCounter];
  121.    ball._y = recordY[playCounter];
  122.    if(playCounter > recordX.length)
  123.    {
  124.       if(playLoop)
  125.       {
  126.          playCounter = 0;
  127.       }
  128.       else
  129.       {
  130.          playCounter = recordX.length;
  131.       }
  132.    }
  133.    if(playCounter < 0)
  134.    {
  135.       playCounter = 0;
  136.    }
  137. }
  138. function bitmapLine(startx, starty, endx, endy)
  139. {
  140.    myX = Array();
  141.    myY = Array();
  142.    x3 = (endx - startx) / 100;
  143.    y3 = (endy - starty) / 100;
  144.    a = 1;
  145.    while(a < 101)
  146.    {
  147.       startx += x3;
  148.       starty += y3;
  149.       myX.push(startx);
  150.       myY.push(starty);
  151.       a++;
  152.    }
  153.    a = 1;
  154.    while(a < 101)
  155.    {
  156.       bmp1.setPixel32(myX[a - 1],myY[a - 1],872415231);
  157.       a++;
  158.    }
  159. }
  160. function clearBitmap()
  161. {
  162.    bmp1.fillRect(new flash.geom.Rectangle(0,0,550,550),0);
  163.    olderX = ball._x;
  164.    olderY = ball._y;
  165. }
  166. function drawPath()
  167. {
  168.    if(!hitBomb)
  169.    {
  170.       bitmapLine(ball._x,ball._y,olderX,olderY);
  171.       olderX = ball._x;
  172.       olderY = ball._y;
  173.    }
  174. }
  175. function goalDetection()
  176. {
  177.    if(ball.hitTest(levels.goal.hitA))
  178.    {
  179.       globalPause = true;
  180.       shel = attachMovie("levelComplete","levelComplete",k++);
  181.       shel._x = levels.goal._x;
  182.       shel._y = levels.goal._y;
  183.       tempNumber = Number(totUp + totDown + totLeft + totRight);
  184.       if(myTimes[level - 1] == 0)
  185.       {
  186.          myTimes[level - 1] = tempNumber;
  187.       }
  188.       else if(myTimes[level - 1] > tempNumber)
  189.       {
  190.          myTimes[level - 1] = tempNumber;
  191.       }
  192.       saveGame();
  193.    }
  194. }
  195. function triggerLevelMenu()
  196. {
  197.    shel = attachMovie("levelMenu","levelMenu",k++);
  198.    shel._x = 93;
  199.    shel._y = 230;
  200.    shel.levelMenuDisp.text = "Level " + level + " Completed!";
  201. }
  202. function resetMap()
  203. {
  204.    ball._x = levels.startPoint._x;
  205.    ball._y = levels.startPoint._y;
  206.    xVel = 0;
  207.    yVel = 0;
  208.    totRings = ringsOnLevels[level - 1];
  209.    i = 1;
  210.    while(i <= totRings)
  211.    {
  212.       levels.goal["ring" + i]._visible = false;
  213.       levels["rSwitch" + i]._visible = true;
  214.       i++;
  215.    }
  216.    i = totRings + 1;
  217.    while(i <= 4)
  218.    {
  219.       levels.goal["ring" + i]._visible = true;
  220.       levels["rSwitch" + i]._visible = false;
  221.       i++;
  222.    }
  223.    i = 1;
  224.    while(i <= 4)
  225.    {
  226.       levels["rSwitch" + i].gotoAndStop(1);
  227.       i++;
  228.    }
  229.    if(totRings != 0)
  230.    {
  231.       levels.goal.gotoAndStop(2);
  232.    }
  233.    ringsCollected = 0;
  234. }
  235. function ringsHad()
  236. {
  237.    i = 1;
  238.    while(i <= 4)
  239.    {
  240.       if(ball.hitTest(levels["rSwitch" + i]))
  241.       {
  242.          if(levels["rSwitch" + i]._visible && levels["rSwitch" + i]._currentframe == 1)
  243.          {
  244.             ringsCollected++;
  245.             levels.goal["ring" + i]._visible = true;
  246.             levels["rSwitch" + i].gotoAndStop(2);
  247.             shel = attachMovie("liner","liner" + k,k++);
  248.             shel._x = 0;
  249.             shel._y = 0;
  250.             switch(i)
  251.             {
  252.                case 1:
  253.                   hexy = 13209;
  254.                   break;
  255.                case 2:
  256.                   hexy = 16711680;
  257.                   break;
  258.                case 3:
  259.                   hexy = 13408512;
  260.                   break;
  261.                case 4:
  262.                   hexy = 9657208;
  263.             }
  264.             shel.flip.lineStyle(10,hexy,50);
  265.             shel.flip.moveTo(levels["rSwitch" + i]._x,levels["rSwitch" + i]._y);
  266.             shel.flip.lineTo(levels._x + levels.goal._x,levels._y + levels.goal._y);
  267.             shel.flip.lineStyle(2,hexy,100);
  268.             shel.flip.moveTo(levels["rSwitch" + i]._x,levels["rSwitch" + i]._y);
  269.             shel.flip.lineTo(levels._x + levels.goal._x,levels._y + levels.goal._y);
  270.          }
  271.       }
  272.       i++;
  273.    }
  274.    if(ringsCollected == totRings)
  275.    {
  276.       levels.goal.gotoAndStop(1);
  277.    }
  278. }
  279. function resetRecordMemory()
  280. {
  281.    recordX.splice(0,recordX.length);
  282.    recordY.splice(0,recordY.length);
  283. }
  284. function record()
  285. {
  286.    recordX.push(ball._x);
  287.    recordY.push(ball._y);
  288. }
  289. function ballColors()
  290. {
  291.    ball.gotoAndStop(2);
  292. }
  293. function depths()
  294. {
  295.    drawArea.swapDepths(k++);
  296.    ball.swapDepths(k++);
  297. }
  298. function compulseReactions()
  299. {
  300.    i = 0;
  301.    while(i < compulses.length)
  302.    {
  303.       tile = holder[compulses[i]];
  304.       if(tile.hitA.hitTest(ball))
  305.       {
  306.          switch(tile.type)
  307.          {
  308.             case "left":
  309.                xVel -= boostSpeed;
  310.                break;
  311.             case "right":
  312.                xVel += boostSpeed;
  313.                break;
  314.             case "up":
  315.                yVel -= boostSpeed;
  316.                break;
  317.             case "down":
  318.                yVel += boostSpeed;
  319.          }
  320.       }
  321.       i++;
  322.    }
  323. }
  324. function boundaries()
  325. {
  326.    if(ball._y + radius > 460)
  327.    {
  328.       yVel = - Math.abs(yVel);
  329.       ball._y = 460 - radius;
  330.       yDamper();
  331.    }
  332.    if(ball._y - radius < 10)
  333.    {
  334.       yVel = Math.abs(yVel);
  335.       ball._y = 10 + radius;
  336.       yDamper();
  337.    }
  338.    if(ball._x + radius > 540)
  339.    {
  340.       xVel = - Math.abs(xVel);
  341.       ball._x = 540 - radius;
  342.       xDamper();
  343.    }
  344.    if(ball._x - radius < 10)
  345.    {
  346.       xVel = Math.abs(xVel);
  347.       ball._x = 10 + radius;
  348.       xDamper();
  349.    }
  350. }
  351. function ballVelocity()
  352. {
  353.    yVel += gravity;
  354.    ball._x += xVel;
  355.    ball._y += yVel;
  356. }
  357. function xDamper()
  358. {
  359.    xVel *= 0.9;
  360.    if(Math.abs(xVel) > 2)
  361.    {
  362.       rav.start(0,1);
  363.    }
  364. }
  365. function yDamper()
  366. {
  367.    yVel *= 0.9;
  368.    if(Math.abs(yVel) > 2)
  369.    {
  370.       rav.start(0,1);
  371.    }
  372. }
  373. function triggerStoppage()
  374. {
  375.    cStatus = false;
  376.    ball._visible = true;
  377.    ball.gotoAndStop(1);
  378.    resetMap();
  379.    resetRecordMemory();
  380.    goButton._visible = true;
  381.    stopButton._visible = false;
  382.    resetButton._visible = true;
  383. }
  384. stop();
  385. var ringSpeed = 3;
  386. var cStatus = false;
  387. var gravity = 0.3;
  388. var gDirection = "down";
  389. var xVel = 0;
  390. var yVel = 0;
  391. var boostSpeed = 1;
  392. var radius = ball._width / 2;
  393. var totUp = 0;
  394. var totDown = 0;
  395. var totLeft = 0;
  396. var totRight = 0;
  397. var globalPause = false;
  398. var level = levChoice;
  399. var levelDisp = "L" + level;
  400. levels.gotoAndStop(level);
  401. callDescriptions();
  402. var recordX = new Array();
  403. var recordY = new Array();
  404. var playCounter = 0;
  405. var playLoop = false;
  406. var playMode = "paused";
  407. var mainMode = "normal";
  408. onEnterFrame = function()
  409. {
  410.    callDescriptions();
  411.    if(!globalPause)
  412.    {
  413.       if(cStatus)
  414.       {
  415.          if(mainMode == "normal")
  416.          {
  417.             mainRings();
  418.             ballColors();
  419.             compulseReactions();
  420.             boundaries();
  421.             ballVelocity();
  422.             record();
  423.             depths();
  424.             goalDetection();
  425.             ringsHad();
  426.             drawPath();
  427.          }
  428.          else if(mainMode == "instantReplay")
  429.          {
  430.             playPoints();
  431.          }
  432.       }
  433.    }
  434. };
  435. var bmp1 = new flash.display.BitmapData(550,550,true,0);
  436. drawArea.attachBitmap(bmp1,k++);
  437. var olderX = 0;
  438. var olderY = 0;
  439. var hitBomb = false;
  440. var totRings = 0;
  441. var ringsCollected = 0;
  442. resetMap();
  443. var compulses = new Array();
  444. var rav = new Sound(this);
  445. rav.attachSound("wood3");
  446. var k = 0;
  447. var foundLove = false;
  448. var dropOne = true;
  449. _root.createEmptyMovieClip("holder",k++);
  450. onMouseDown = function()
  451. {
  452.    if(!cStatus && !globalPause)
  453.    {
  454.       dropOne = true;
  455.       i = 0;
  456.       while(i < compulses.length)
  457.       {
  458.          if(holder[compulses[i]].hitA.hitTest(_xmouse,_ymouse))
  459.          {
  460.             dropOne = false;
  461.          }
  462.          i++;
  463.       }
  464.       foundLove = false;
  465.       if(leftTileButton.hitA.hitTest(_xmouse,_ymouse))
  466.       {
  467.          shel = holder.attachMovie("leftTile","l" + k,k++);
  468.          shel.type = "left";
  469.          foundLove = true;
  470.          totLeft++;
  471.       }
  472.       else if(upTileButton.hitA.hitTest(_xmouse,_ymouse))
  473.       {
  474.          shel = holder.attachMovie("upTile","l" + k,k++);
  475.          shel.type = "up";
  476.          foundLove = true;
  477.          totUp++;
  478.       }
  479.       else if(rightTileButton.hitA.hitTest(_xmouse,_ymouse))
  480.       {
  481.          shel = holder.attachMovie("rightTile","l" + k,k++);
  482.          shel.type = "right";
  483.          foundLove = true;
  484.          totRight++;
  485.       }
  486.       else if(downTileButton.hitA.hitTest(_xmouse,_ymouse))
  487.       {
  488.          shel = holder.attachMovie("downTile","l" + k,k++);
  489.          shel.type = "down";
  490.          foundLove = true;
  491.          totDown++;
  492.       }
  493.       else
  494.       {
  495.          i = 0;
  496.          while(i < compulses.length)
  497.          {
  498.             if(holder[compulses[i]].hitTest(_xmouse,_ymouse))
  499.             {
  500.                holder[compulses[i]].startDrag();
  501.             }
  502.             i++;
  503.          }
  504.       }
  505.       if(foundLove)
  506.       {
  507.          shel._x = _xmouse;
  508.          shel._y = _ymouse;
  509.          shel.startDrag(true);
  510.          compulses.push("l" + k);
  511.       }
  512.    }
  513.    trace(compulses);
  514. };
  515. onMouseUp = function()
  516. {
  517.    i = 0;
  518.    while(i < compulses.length)
  519.    {
  520.       holder[compulses[i]].stopDrag();
  521.       if(holder[compulses[i]]._y > 460)
  522.       {
  523.          switch(holder[compulses[i]].type)
  524.          {
  525.             case "left":
  526.                totLeft--;
  527.                break;
  528.             case "right":
  529.                totRight--;
  530.                break;
  531.             case "up":
  532.                totUp--;
  533.                break;
  534.             case "down":
  535.                totDown--;
  536.          }
  537.          holder[compulses[i]].removeMovieClip();
  538.          compulses.splice(i,1);
  539.       }
  540.       i++;
  541.    }
  542. };
  543. goButton._visible = true;
  544. stopButton._visible = false;
  545. goButton.onRelease = function()
  546. {
  547.    hitBomb = false;
  548.    if(!globalPause && mainMode == "normal")
  549.    {
  550.       drawArea.clear();
  551.       drawArea.moveTo(ball._x,ball._y);
  552.       clearBitmap();
  553.       cStatus = true;
  554.       stopButton._visible = true;
  555.       goButton._visible = false;
  556.       resetButton._visible = false;
  557.    }
  558. };
  559. stopButton.onRelease = function()
  560. {
  561.    if(!globalPause && mainMode == "normal")
  562.    {
  563.       triggerStoppage();
  564.    }
  565. };
  566. resetButton.onRelease = function()
  567. {
  568.    if(!globalPause && mainMode == "normal")
  569.    {
  570.       drawArea.clear();
  571.       clearBitmap();
  572.       resetCompulses();
  573.    }
  574. };
  575.